//
//  WYCTabBarController.m
//  WYCweibo
//
//  Created by 魏云超 on 15/11/10.
//  Copyright (c) 2015年 魏云超. All rights reserved.
//

#import "WYCTabBarController.h"

@interface WYCTabBarController ()

@end

@implementation WYCTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //1.添加子控制器
    [self addChildViewControllers];
}
-(void)addChildViewControllers{

    [self addChildVCWithSBName:@"WYCHomeController" title:@"首页" norImageName:@"tabbar_home" selectedImageName:@"tabbar_home_highlighted"];
    [self addChildVCWithSBName:@"WYCMessageController" title:@"消息" norImageName:@"tabbar_message_center" selectedImageName:@"tabbar_message_center_highlighted"];
    [self addChildVCWithSBName:@"WYCDiscoverController" title:@"发现" norImageName:@"tabbar_discover" selectedImageName:@"tabbar_discover_highlighted"];
    [self addChildVCWithSBName:@"WYCProfileController" title:@"我" norImageName:@"tabbar_home" selectedImageName:@"tabbar_home_highlighted"];
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
//    for (UIView *subview in self.tabBar.subviews) {
//        subview.frame = CGRectMake(0, 0, 100, 100);
//    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)addChildVCWithClass:(Class)class title:(NSString *)title norImageName:(NSString *)norImageName selectedImageName:(NSString *)selectedImageName{
    UIViewController *vc4 = [[UIViewController alloc]init];
    [self addChildVCWithController:vc4 title:title norImageName:norImageName selectedImageName:selectedImageName];
}
-(void)addChildVCWithSBName:(NSString *)sbName title:(NSString *)title norImageName:(NSString *)norImageName selectedImageName:(NSString *)selectedImageName{
    //加载storyboard
    UIStoryboard *sb = [UIStoryboard storyboardWithName:sbName bundle:nil];
    //创建stroyboard控制器
    UINavigationController *vc = sb.instantiateInitialViewController;
    //调用方法
    [self addChildVCWithController:vc.topViewController title:title norImageName:norImageName selectedImageName:selectedImageName];
}
-(void) addChildVCWithController:(UIViewController *)vc title:(NSString *)title norImageName:(NSString *)norImageName selectedImageName:(NSString *)selectedImageName{
    
    vc.tabBarItem.title = title;
    vc.navigationItem.title = title;
    vc.tabBarItem.image = [UIImage imageNamed:norImageName];
    //设置图片选中是 不适用系统渲染tingcolor 适配ios7
    UIImage *selectedIMG = [UIImage imageNamed:selectedImageName];
    selectedIMG = [selectedIMG imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    vc.tabBarItem.selectedImage = selectedIMG;
    self.tabBar.tintColor = [UIColor orangeColor];
//    vc.view.backgroundColor = WYCRandomColor;
    [self addChildViewController:vc.navigationController];
}

@end
